/*    */ package com.zimbra.cs.redolog.op;
/*    */ 
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.cs.mailbox.MailboxOperation;
/*    */ import com.zimbra.cs.redolog.RedoLogInput;
/*    */ import com.zimbra.cs.redolog.RedoLogOutput;
/*    */ import java.io.IOException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.HashMap;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class SetImapUid
/*    */   extends RedoableOp
/*    */ {
/* 37 */   private Map<Integer, Integer> mImapUids = new HashMap();
/*    */   
/*    */   public SetImapUid() {
/* 40 */     super(MailboxOperation.SetImapUid);
/*    */   }
/*    */   
/*    */   public SetImapUid(int mailboxId, List<Integer> msgIds) {
/* 44 */     this();
/* 45 */     setMailboxId(mailboxId);
/* 46 */     for (Iterator i$ = msgIds.iterator(); i$.hasNext();) { int id = ((Integer)i$.next()).intValue();
/* 47 */       this.mImapUids.put(Integer.valueOf(id), Integer.valueOf(0));
/*    */     }
/*    */   }
/*    */   
/* 51 */   public int getImapUid(int msgId) { Integer imapUid = (Integer)this.mImapUids.get(Integer.valueOf(msgId));
/* 52 */     int uid = imapUid == null ? -1 : imapUid.intValue();
/* 53 */     return uid == 0 ? -1 : uid;
/*    */   }
/*    */   
/*    */   public void setImapUid(int msgId, int imapId) {
/* 57 */     this.mImapUids.put(Integer.valueOf(msgId), Integer.valueOf(imapId));
/*    */   }
/*    */   
/*    */   protected String getPrintableData() {
/* 61 */     StringBuilder sb = new StringBuilder();
/* 62 */     for (Map.Entry<Integer, Integer> entry : this.mImapUids.entrySet())
/* 63 */       sb.append(sb.length() == 0 ? "" : ", ").append(entry.getKey()).append('=').append(entry.getValue());
/* 64 */     return sb.toString();
/*    */   }
/*    */   
/*    */   protected void serializeData(RedoLogOutput out) throws IOException {
/* 68 */     out.writeInt(this.mImapUids.size());
/* 69 */     for (Map.Entry<Integer, Integer> entry : this.mImapUids.entrySet()) {
/* 70 */       out.writeInt(((Integer)entry.getKey()).intValue());
/* 71 */       out.writeInt(((Integer)entry.getValue()).intValue());
/*    */     }
/*    */   }
/*    */   
/*    */   protected void deserializeData(RedoLogInput in) throws IOException {
/* 76 */     int count = in.readInt();
/* 77 */     for (int i = 0; i < count; i++) {
/* 78 */       int msgId = in.readInt();
/* 79 */       this.mImapUids.put(Integer.valueOf(msgId), Integer.valueOf(in.readInt()));
/*    */     }
/*    */   }
/*    */   
/*    */   public void redo() throws Exception {
/* 84 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/* 85 */     mbox.resetImapUid(getOperationContext(), new ArrayList(this.mImapUids.keySet()));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/SetImapUid.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */